﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FSM.IBll;
using FSM.Model;
using FSM.Web.Models;
using FSM.Web.Models.Fileter;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Util.Helper;

namespace FSM.Web.Controllers
{
    public class HomeController : Controller
    {
        #region 字段

        private readonly DataResultModel drm;

        private readonly ISysMenuBll _menuBll;

        private ILogger<HomeController> _logger;

        #endregion

        #region 构造函数

        public HomeController(ISysMenuBll menuBll, ILogger<HomeController> logger)
        {
            _menuBll = menuBll;
            drm = new DataResultModel();
            this._logger = logger;
        }

        #endregion

        [Authorize]
        public IActionResult Index()
        {
            return View();
        }

        [Authorize]
        [HttpPost]
        [ResultExceptionFilter]
        public JsonResult Menus()
        {
            string userNo = AuthencationHelper.GetLoginUserNo(User);
            List<sys_menu> tree = _menuBll.TreeByUser(userNo);
            drm.data = tree;
            drm.success = true;
            return drm.ToJson();
        }

        public IActionResult LogOut()
        {
            HttpContext.SignOutAsync();
            return RedirectToAction("Index", "Login");
        }
    }
}
